import VPlay 1.0
import QtQuick 1.1
// Plugins
import VPlay.plugins.gamecenter 1.0
import VPlay.plugins.flurry 1.0

GameWindow {
    id: window
    // depending on which window size is defined as start resolution here, the corresponding image sizes get loaded here! so for testing hd2 images, at least use factor 3.5
    // the window size can be changed at runtime by pressing the keys 1-6 (see GameWindow.qml)
    width: 320//*2//*1.5 // for testing on desktop with the highest res, use *1.5 so the -hd2 textures are used
    height: 480//*2//*1.5

    // for better readability of the fps for QML renderer
    fpsTextItem.color: "white"


    EntityManager {
        id: entityManager
        entityContainer: gameScene.entityContainer
        poolingEnabled: true // entity pooling works since version 0.9.4, so use it
    }




    // menu scene
    MenuScene {
        id: menuScene
        onSelectLevelPressed: window.state = "selectLevel"
        onCreditsPressed: window.state = "credits"
    }



    // scene for selecting levels
    SelectLevelScene {
        id: selectLevelScene
        onLevelPressed: window.state = "game"
        onBackPressed: window.state = "menu"

    }

    // credtis scene
    CreditsScene {
        id: creditsScene
        onBackPressed: window.state = "menu"
    }

    // game scene to play a level
    GameScene {
        id: gameScene
        onBackPressed: window.state = "selectLevel"
    }

    // default state is menu -> default scene is menuScene
    state: "menu"

    // state machine, takes care reversing the PropertyChanges when changing the state like changing the opacity back to 0
    states: [
        State {
            name: "menu"
            PropertyChanges {target: menuScene; opacity: 1}
            PropertyChanges {target: window; activeScene: menuScene}
        },
        State {
            name: "selectLevel"
            PropertyChanges {target: selectLevelScene; opacity: 1}
            PropertyChanges {target: window; activeScene: selectLevelScene}
        },
        State {
            name: "credits"
            PropertyChanges {target: creditsScene; opacity: 1}
            PropertyChanges {target: window; activeScene: creditsScene}
        },
        State {
            name: "game"
            PropertyChanges {target: gameScene; opacity: 1}
            PropertyChanges {target: window; activeScene: gameScene}
            StateChangeScript {
                script: {
                    gameScene.setLevel(selectLevelScene.selectedLevel)
                }
            }
        }
    ]
    // every change in opacity will be done with an animation
    transitions: [
        Transition {
            NumberAnimation {property: "opacity"; easing.type: Easing.InOutQuad}
        }
    ]
}
